<?php

	
	class FileUploadView {
		
		private $m_fileList;
		private $m_triedToUpload = "TriedToUpload";
		private $m_getUpload = "UploadedFile";
		private $fh;
		
		//Konstruktor
		public function __construct(FileUploadHandler $fileUploadHandler){
			$this->fh = $fileUploadHandler;
		}
		
		//Returnerar  html för uppladdning
		public function DoUploadform(){
				$ret = "
		<div id='fileUpload'>
			<form method='post' enctype='multipart/form-data'>
				<fieldset>
					<legend>Upload File</legend>
						<p>
							<label for='file'>Filename: </label><input type='file' name='$this->m_getUpload' id='file'/>
						</p>
						<input class='button' type='submit' name='$this->m_triedToUpload' value='Upload'/>
				</fieldset>
			</form>
		</div>";
			return $ret;
		}
		
		//Returnerar  html för meddelanden
		public function DoFeedback($message){
			return "
		<div id='feedback'>
			<p>$message</p>
		</div>";
		}
		
		//Returnerar  html för listan
		public function DoFileList(){
			 $this->m_fileList ="
		 <div id='fileList'>
		 	<h2>Uploaded files:</h2>
		 	<ul>";
			 //Hämtar en array med filnamn och skriver ut dem
			 foreach($this->fh->GetFiles() as $file){
			 	$this->m_fileList .= "
		<li>
			<a href='Files/$file' title='$file' ><img src='Files/$file' width='120px' height='90px' />$file</a>
		</li>";
			 }
			 
			 $this->m_fileList .= "
 			</ul>
		</div>";
			return $this->m_fileList;
		}
		
		//Hämtar filen och sparar den.
		public function GetUpload(){
			if (isset( $_FILES[$this->m_getUpload]) === true) {
				return $_FILES[$this->m_getUpload];
			}
			return FALSE;
		}
		
		//Kollar om användaren försöker ladda upp en fil.
		public function TriedToUpload() {
			
	    	if (isset( $_POST[$this->m_triedToUpload]) === true) {
				return TRUE;
			}
	    	return FALSE;
  		}
	}
?>